home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13734 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  55 lines

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: URGENT..Help Needed!!
  5. Date: Tue, 26 Mar 1996 20:07:02 -0500
  6. Organization: Datalytics, Inc
  7. Message-ID: <315894B6.6A78@datalytics.com>
  8. References: <4j0h0u$9dj$1@sydney.DIALix.oz.au>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. A and K Gonzalez wrote:
  16. > My main questions are how do initialise an array to zero or set them with
  17. > spaces?
  18. > Assuming you are using a character array, and are not using a 
  19. class to encapsulate the vector (array) behavior, try this:
  20.  
  21. #include <string.h>        // memcpy
  22.  
  23. char* p = new char[MAX_LENGTH];
  24. memcpy(
  25.     p,
  26.     0,            // or ' '
  27.     MAX_LENGTH);
  28.  
  29. > How can I search through my arrays looking for a space in them? Do I use
  30. > a while loop??
  31. > Using the array allocated above:
  32.  
  33. #include <stddef.h>        // size_t
  34.  
  35. for (size_t i = 0; i < MAX_LENGTH; i++)
  36. {
  37.     if (p[i] == ' ')    // if found a space
  38.     {
  39.         // do whatever is important when you find it
  40.         break;        // if find only one
  41.     }
  42. }
  43.  
  44. > And lastly, how do I list all items in the array, one per line??
  45. > #include <iostream.h>        // cout
  46.  
  47. for (size_t i = 0; i < MAX_LENGTH; i++)
  48. {
  49.     cout << "p[" << i << "] == " << p[i] << endl;
  50. }
  51.  
  52. -- 
  53. Robert Stewart        | My opinions are usually my own.
  54. Datalytics, Inc.    | stew@datalytics.com
  55.